refactor(core): route title and compaction through shared model requests - #43555
Merged
Conversation
kitlangton
enabled auto-merge (squash)
August 20, 2026 03:19
# ------------------------ >8 ------------------------ # Do not modify or remove the line above. # Everything below it will be ignored. # # Conflicts: # packages/core/src/session/compaction.ts # packages/core/src/session/runner/llm.ts # packages/core/test/config/compaction.test.ts # packages/core/test/session-compaction.test.ts
kitlangton
disabled auto-merge
August 20, 2026 03:40
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Routes the two remaining hand-rolled session-scoped LLM request envelopes — title generation and compaction summaries — through the shared
SessionModelRequest.prepareboundary established in #42680. Callers keep policy (transcript selection, streaming, usage recording, event publishing); prepare owns all provider-visible shaping.Before / After
session/title.ts(title generation)titleagent's model (or session model fallback) viaSessionRunnerModel.resolvepreparescopeSessionModelHeaders.makemodel.requesthooksSessionModelHook.applytools: []Tool.Snapshot→ still[]on the wirewebSocketnever passed); hook middleware attached only when HTTP hooks are registered, matching the runnersession/compaction.ts(compaction summary)model/ref/costfieldsSessionRunnerModel.Resolvedcarried throughAutoInput/PlanSessionPromptCacheKey.make(session.id)— a forked session used its own idmodel.requesthookstools: []Tool.Snapshot→ still[]on the wirewebSocketnever passed); hook middleware attached only when HTTP hooks are registeredAudited and left alone
core/src/generate.ts(Generate.text) — a generic, non-session generate utility. It has no session scope: no session ID, no agent, no session headers, cache key, or hooks apply. Putting it behind a session-scoped boundary would invent scope it does not have, so it stays onLLMClient.generatedirectly.webSocket: "session"opt-in remains exclusive to the durable runner; neither title nor compaction passes it.Session context hooks stay away from title and compaction requests.
Unification must not change observable plugin behavior: title and compaction requests never ran
session.contexthooks before, so they still do not.preparegains acontextHooks: falseopt-out — context hooks shape the agent conversation, and title/compaction requests are not part of it, so their transcripts pass through unchanged — and both behaviors are pinned by tests ("keeps session context hooks away from title/compaction requests"). Conversation requests (runner,session.generate) keep running them.scope.toolsalso became optional: title and compaction requests carry no tools, and the empty snapshot now lives at the boundary that required it instead of duplicated at each call site.How
SessionTitleandSessionCompactionnow depend onSessionModelRequest.Serviceand build their requests withprepare({ scope, transcript }), dropping their private uses ofSessionModelHeaders,SessionModelHook,SessionModelHttp,SessionPromptCacheKey,PluginHooks, andApp.Tool.Snapshot;Prepared.executeToolis unused since neither site executes tools.SessionCompaction.AutoInput/Plancollapsemodel/ref/costinto oneSessionRunnerModel.Resolved; the runner'scompactionInputpassesloaded.modeldirectly.Prepared; policy stays in the callers.Scope
packages/core/src/session/title.tspackages/core/src/session/compaction.tspackages/core/src/session/runner/llm.ts(compaction input shape only)packages/core/test/session-title.test.ts,test/session-compaction.test.ts,test/config/compaction.test.ts(fixture shape + new coverage).changeset/unify-request-envelope.mdTesting
session.contexthook now reaches title requests; forked-session compaction asserts the fork root prompt cache key.bun typecheckandbun run testfrompackages/core: 1891 pass, 0 fail.